package com.mywork.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ciko.code.bean.WorkMeetingListBean;
import com.ciko.code.utils.DateUtil;
import com.mywork.R;

import java.util.List;


/**
 * Created by x_luthy on 2016/3/31.
 */
public class MeetingsAdapter
        extends
        BaseAdapter
{
	private Context	   context;
	private HolderView holder;
	private List<WorkMeetingListBean> list;
	private int TYPE;
	public MeetingsAdapter(Context context, List<WorkMeetingListBean> list, int TYPE) {
		this.context = context;
		this.list = list;
		this.TYPE = TYPE;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int i) {
		return list.get(i);
	}

	@Override
	public long getItemId(int i) {
		return i;
	}

	@Override
	public View getView(int i, View view, ViewGroup viewGroup) {
		if (view == null)
		{
			view = LayoutInflater.from(context).inflate(R.layout.meetings_adapter_item, null);
			holder = new HolderView();
			holder.tvTime = (TextView) view.findViewById(R.id.tv_time);
			holder.tvAddress = (TextView) view.findViewById(R.id.tv_address);
			holder.tvTopic = (TextView) view.findViewById(R.id.tv_topic);
			holder.imgAddress = (ImageView) view.findViewById(R.id.img_address);
			holder.imgTime = (ImageView) view.findViewById(R.id.img_time);
			holder.imgTopic = (ImageView) view.findViewById(R.id.img_topic);
			if (TYPE == 1)
			{
				holder.imgAddress.setImageResource(R.drawable.new_meeting_address_img);
				holder.imgTopic.setImageResource(R.drawable.new_meeting_topic_img);
				holder.imgTime.setImageResource(R.drawable.new_meeting_time_img);

			}
			else {
				holder.imgAddress.setImageResource(R.drawable.old_meeting_address_img);
				holder.imgTopic.setImageResource(R.drawable.old_meeting_topic_img);
				holder.imgTime.setImageResource(R.drawable.old_meeting_time_img);
			}
			view.setTag(holder);
		}
		else
		{
			holder = (HolderView) view.getTag();
		}
		String strTime = DateUtil.longToDate(list.get(i).getMeetingTime(), 8);
//		holder.tvTime.setText(strTime.substring(0, 4) + "年" + strTime.substring(5, 7) + "月" + strTime.substring(8, 10) + "日" + "  " + strTime.substring(11, 13) + "点");
		holder.tvTime.setText(strTime.substring(5, 7) + "月" + strTime.substring(8, 10) + "日" + "  " + strTime.substring(11, 13) + "点" + strTime.substring(14, 16) + "分");
		holder.tvAddress.setText(list.get(i).getAddress());
		holder.tvTopic.setText(list.get(i).getTitle());
		return view;
	}

	private class HolderView
	{
		TextView tvAddress, tvTopic, tvTime;
		ImageView imgAddress, imgTopic, imgTime;
	}
}
